home *** CD-ROM | disk | FTP | other *** search
/ Developer Helper 1: Phil & Dave's Excellent CD / Excellent CD HFS.raw / Utilities / ResEdit / Examples / PExamples / Source / ICONLDEF.p < prev    next >
Text File  |  2022-08-05  |  2KB  |  84 lines

  1. {
  2.  COPYRIGHT (C) 1984-1989 Apple Computer,Inc.
  3.  All rights reserved
  4. }
  5. UNIT IconLDEF;
  6.  
  7. INTERFACE
  8.  
  9. Uses    MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
  10.             ResEd;
  11.  
  12. PROCEDURE DrawCell( Message: INTEGER; lSelect: BOOLEAN; lRect: Rect; lCell: Point;
  13.                     lDataOffset, lDataLen: INTEGER; lh: ListHandle );
  14.  
  15. IMPLEMENTATION
  16.  
  17. { This is the custom drawProc for the list (which contains the resource ID's).  It
  18.     simply draws the icon in the given rect and frames a selection rect around it if
  19.     told to. }
  20. PROCEDURE DrawCell(Message: INTEGER; lSelect: BOOLEAN; lRect: Rect; lCell: Point;
  21.                    lDataOffset, lDataLen: INTEGER; lh: ListHandle);
  22.  
  23. VAR
  24.     i: Handle;
  25.     
  26.     { This routine simply looks up in the list at the given cell, extracts the ID and
  27.         gets the resource called for.  Returns NIL if not found.  Note, this assumes
  28.         the resfile is set up correctly }
  29.     FUNCTION  IconFetch(lCell: point; lHandle: ListHandle): Handle ;
  30.     CONST IconSize = 128;
  31.  
  32.     VAR
  33.         offset, len, id: INTEGER;
  34.         tempH:Handle;
  35.         
  36.     BEGIN
  37.     IconFetch := NIL;
  38.     len:=2;
  39.     LGetCell(@id, len, lCell, lHandle);    { Get the ID from the list. }
  40.     IF len > 0 THEN
  41.         BEGIN    { Load the resource since we want to draw it. }
  42.         tempH:=Get1Res('ICON', id );
  43.         IF (SizeResource(tempH) < IconSize) THEN
  44.             IconFetch := NIL    { Bad resource. }
  45.         ELSE
  46.             IconFetch := tempH;
  47.         END;
  48.     END;
  49.  
  50. BEGIN    { DrawCell }
  51. CASE  message OF
  52.     lInitMsg:
  53.         BEGIN
  54.         WITH lh^^.indent DO
  55.             BEGIN
  56.             h := 8;
  57.             v := 8;
  58.             END;
  59.         END;
  60.     lDrawMsg, lHiliteMsg:
  61.         BEGIN
  62.         { Always use the right sized rectangle. }
  63.         lRect.bottom := lRect.top + lh^^.cellSize.v;
  64.         lRect.right := lRect.left + lh^^.cellSize.h;
  65.         
  66.         i := IconFetch(lCell, lh);
  67.         EraseRect(lRect);
  68.         InsetRect(lRect, lh^^.indent.h, lh^^.indent.v);
  69.         IF lSelect THEN
  70.             FrameRect(lRect);    { Select the icon by framing it. }
  71.         IF i <> NIL THEN
  72.             BEGIN
  73.             IF i^ <> NIL THEN
  74.                 BEGIN
  75.                 InsetRect(lRect, lh^^.indent.h, lh^^.indent.v);
  76.                 PlotIcon(lRect, i);
  77.                 END;
  78.             END;
  79.         END;
  80.     END;
  81. END;
  82.  
  83. END.
  84.